<form id="form_grade"  
name="form_grade" 
action="<?php echo url_for('grade_turma/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id_grade_turma='.$form->getObject()->getIdDisciplina() : '')) ?>" 
method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>
class="form-horizontal"
>

<input type="hidden" name="grade_turma[id_turma_ano_letivo]" value="<?php echo $id_turma_ano_letivo; ?>" />
<input type="hidden" name="grade_turma[nu_dia_semana]" value="<?php echo $dia; ?>" />

<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<input type="hidden" name="id_grade_turma" value="<?php echo $form->getObject()->getIdGradeTurma() ?>" />
<?php endif; ?>
	
	<fieldset> 
	<table class="table table-striped table-bordered table-condensed">
        <tbody>
          <tr>
            <td><h5>Horário</h5></td>
            <?php for($i=0; $i<4; $i++):?>
            <td>
            	<?php echo $form['form_hora_inicio'][$i]->render(array('value' => (isset($grade_turma[$i])) ? Util::hour($grade_turma[$i]['nu_hora_inicio']) : ''))
            			." a ".
            			$form['form_hora_fim'][$i]->render(array('value' => (isset($grade_turma[$i])) ? Util::hour($grade_turma[$i]['nu_hora_fim']) : '')); ?>
            </td>
            <?php endfor; ?>
          </tr>
          <tr>
            <td><h5>Disciplina</h5></td>
            <?php for($i=0; $i<4; $i++):?>
            <td>
            	<?php echo $form['form_disciplina'][$i]->render(array('value' => (isset($grade_turma[$i])) ? $grade_turma[$i]['Disciplina']['nm_disciplina'] : ''))
            			. " ".
            				$form['form_id_disciplina'][$i]->render(array('value' => (isset($grade_turma[$i])) ? $grade_turma[$i]['Disciplina']['id_disciplina'] : '')); ?>
            </td>
            <?php endfor; ?>
          </tr>
          <tr>
          	<td>
            	<h5>Docente:</h5>
          	</td>
            <?php for($i=0; $i<4; $i++):?>
            <td>
            	<?php echo $form['form_docente'][$i]->render(array('value' => (isset($grade_turma[$i])) ? $grade_turma[$i]['Docente']['nm_docente'] : ''))
            		. " ".
            				$form['form_id_docente'][$i]->render(array('value' => (isset($grade_turma[$i])) ? $grade_turma[$i]['Docente']['id_docente'] : '')); ?>
            </td>
            <?php endfor; ?>
          </tr>
        </tbody>
    </table>
   </fieldset>


<?php
	comandos_form(
		null,
		'<button type="submit" class="btn btn-info">:: Salvar ::</button>'
	);
?>
</form>


<script>
    $(function()
        {
        	var selected = $('.tabs').tabs('option', 'selected');

        	System.formdata.save(new Array("msgAlerta", "Atenção:"), true, "$('.tabs').tabs('load',"+selected+");");

			$('.hora').mask('99:99');
            
            $('.disciplina').autocomplete(
            		{
                		source: <?php echo $disciplinas; ?>,
                        select: function(e, ui){
							$(this).val(ui.item.label);
							$(this).next('input:hidden').val(ui.item.id);
                    	}
            		}
            );

            $('.docente').autocomplete(
            		{
                		source: <?php echo $docentes; ?>,
                        select: function(e, ui){
							$(this).val(ui.item.label);
							$(this).next('input:hidden').val(ui.item.id);
                    	}
            		}
            );
        }
    );
</script>

<?php preenche_mensagem_flash() ?>